package com.derbysoft.synxisadapter.commons.model;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Entity
public class Reservation {


    public enum Status {
        INIT,
        CONFIRMED,
        CANCELLED,
        BOOK_FAILED,
        PREVIEW_FAILED,
        CANCEL_FAILED,
        PREVIEW
    }

    @Id
    @Column(length = 64)
    private String ersp;

    @Column(nullable = false, length = 10)
    private String hotelId;

    @Column(nullable = true, length = 64)
    private String hotelPassport;

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "reservation", cascade = CascadeType.ALL)
    private List<ReservationItem> reservationItems = new ArrayList<ReservationItem>();

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "reservation", cascade = CascadeType.ALL)
    private List<ReservationLog> reservationLogs = new ArrayList<ReservationLog>();

    @Enumerated(EnumType.STRING)
    @Column(nullable = false, length = 20)
    private Status status = Reservation.Status.INIT;

    @Temporal(TemporalType.TIMESTAMP)
    private Date createTime = new Date();

    @Temporal(TemporalType.TIMESTAMP)
    private Date lastUpdateTime;

    public String getErsp() {
        return ersp;
    }

    public void setErsp(String ersp) {
        this.ersp = ersp;
    }

    public String getHotelId() {
        return hotelId;
    }

    public void setHotelId(String hotelId) {
        this.hotelId = hotelId;
    }

    public void setHotelPassport(String hotelPassport) {
        this.hotelPassport = hotelPassport;
    }

    public String getHotelPassport() {
        return hotelPassport;
    }

    public List<ReservationItem> getReservationItems() {
        return reservationItems;
    }

    public void setReservationItems(List<ReservationItem> reservationItems) {
        this.reservationItems = reservationItems;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(Date lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public List<ReservationLog> getReservationLogs() {
        return reservationLogs;
    }

    public void appendLog(ReservationLog reservationLog) {
        reservationLogs.add(reservationLog);
    }
}
